/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package freya.dao;
import freya.util.*;

import freya.model.Sala;
import freya.util.HibernateUtil;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author Danilo Rodrigues
 */
public class SalaDAO implements InterfaceSalaDAO {
    
    Log log = new Log();
    
    private final Session session;
    
    public SalaDAO() {  
        this.session = HibernateUtil.getSessionFactory().getCurrentSession();  
    }

    @Override
    public void Insert(Sala sala) {
        try
        {
        Transaction tx_sala = (Transaction) session.beginTransaction();
        session.save(sala);  
        tx_sala.commit();
        log.cadastroSucessSala();
        }
        catch(Exception e) {
            e.printStackTrace();
            log.erroSalaCadastro();
        }
    }

    @Override
    public List<Sala> List() {
        List<Sala> list = null;
        try
        {
            Transaction tx_sala = (Transaction) session.beginTransaction();
            list = (List<Sala>)session.createQuery("from Sala").list();
            tx_sala.commit();
        }
        catch(Exception e) {
            e.printStackTrace();
        }
        return list;
    }
    
}
